home *** CD-ROM | disk | FTP | other *** search
/ Ray Dream Studio 5 / Ray Dream.iso / pc / DreamSDK / Windows / SAMPLES / ATMOS / FOG / FOGFAC.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-11  |  3.2 KB  |  132 lines

  1. // Copyright (c)1995 Ray Dream, Inc. All Rights Reserved.
  2. /*$Id: FogFac.cpp 1.1 1996/07/18 23:43:07 Damien Exp $*/
  3.  
  4. #ifndef __FOGFAC__
  5. #include "FOGFac.h"
  6. #endif
  7.  
  8. #ifndef __COMFOG__
  9. #include "COMFOG.h"
  10. #endif
  11.  
  12. #ifndef __FOGDLL__
  13. #include "FOGdll.h"
  14. #endif
  15.  
  16.  
  17. // ***** ClassFactory *****
  18.   
  19. AtmosClassFactory::AtmosClassFactory() {
  20.   m_cRef=0L;  // just created so no reference used
  21.   return;
  22.   }
  23.  
  24.  
  25. AtmosClassFactory::~AtmosClassFactory() {
  26.   return;
  27.   }
  28.  
  29. // IUnknown methods of AtmosClassFactory                                                
  30. STDMETHODIMP AtmosClassFactory::QueryInterface(REFIID riid, LPVOID* ppv) {
  31.   *ppv=NULL;
  32.  
  33.   if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IClassFactory))
  34.     *ppv=(LPVOID)this;
  35.  
  36.   if (*ppv!=NULL) {
  37.     ((LPUNKNOWN)*ppv)->AddRef(); // Add reference if we give a pointer
  38.     return NOERROR;
  39.     }
  40.   else {
  41.     return ResultFromScode(E_NOINTERFACE);
  42.     }
  43.   }
  44.  
  45.  
  46. STDMETHODIMP_(ULONG) AtmosClassFactory::AddRef() {
  47.   return ++m_cRef;
  48.   }
  49.  
  50.  
  51. STDMETHODIMP_(ULONG) AtmosClassFactory::Release() {
  52.   ULONG   UnreleaseRef;
  53.  
  54.   UnreleaseRef=--m_cRef;
  55.  
  56.   if (m_cRef == 0)
  57.     delete this; // No reference left, so delete the AtmosClassFactory
  58.  
  59.   return UnreleaseRef;
  60.   }
  61.  
  62. /*
  63.  * AtmosClassFactory::CreateInstance
  64.  *
  65.  * Parameters:
  66.  *  pUnkOuter       LPUNKNOWN to the controlling IUnknown if we are
  67.  *                  being used in an aggregation.
  68.  *  riid            REFIID identifying the interface the caller
  69.  *                  desires to have for the new object.
  70.  *  ppvObj          LPVOID FAR* in which to store the desired
  71.  *                  interface pointer for the new object.
  72.  *
  73.  * Return Value:
  74.  *  HRESULT         NOERROR if successful, otherwise E_NOINTERFACE
  75.  *                  if we cannot support the requested interface.
  76.  */
  77.  
  78. STDMETHODIMP AtmosClassFactory::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, LPVOID FAR* ppvObj) {
  79.   Atmos*      pObj = NULL;
  80.   HRESULT       hr;
  81.  
  82.   *ppvObj = NULL;
  83.   hr = ResultFromScode(E_OUTOFMEMORY);
  84.  
  85.   //Verify that a controlling unknown asks for IUnknown
  86.   if (pUnkOuter && !IsEqualIID(riid, IID_IUnknown))
  87.     return ResultFromScode(E_NOINTERFACE);
  88.  
  89.   //Create the object passing function to notify on destruction.
  90.   if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_I3DExAtmosphericShader))
  91.     pObj = new Atmos;
  92.   else
  93.     return ResultFromScode(E_NOINTERFACE);
  94.  
  95.   hr=pObj->QueryInterface(IID_I3DExAtmosphericShader, ppvObj);
  96.  
  97.   //Kill the object if initial creation failed.
  98.   if (FAILED(hr))
  99.     delete pObj;
  100.   else
  101.     global_count_Obj++;
  102.  
  103.   return hr;
  104.   }
  105.  
  106.  
  107. /*
  108.  * AtmosClassFactory::LockServer
  109.  *
  110.  * Purpose:
  111.  *  Increments or decrements the lock count of the DLL.  If the
  112.  *  lock count goes to zero and there are no objects, the DLL
  113.  *  is allowed to unload.  See DllCanUnloadNow in "atmosdll.cpp".
  114.  *
  115.  * Parameters:
  116.  *  fLock           BOOL specifying whether to increment or
  117.  *                  decrement the lock count.
  118.  *
  119.  * Return Value:
  120.  *  HRESULT         NOERROR always.
  121.  */
  122.  
  123. STDMETHODIMP AtmosClassFactory::LockServer(BOOL fLock) {
  124.   if (fLock)
  125.       global_count_Lock++;
  126.   else
  127.       global_count_Lock--;
  128.  
  129.   return NOERROR;
  130.   }
  131.  
  132.